<?php
	define('DIR_MODELS_EAV', realpath(APPLICATION_PATH . '/../../../data/sites/' . APPLICATION_NAME . '/eav') . '/');
    define('EXT', '.php');
    define('CRLF', "\r\n");
    define('BLADE_EXT', '.blade.php');
    define('DEFAULT_BUNDLE', APPLICATION_NAME);
    define('MB_STRING', (int) function_exists('mb_get_info'));
    defined('WZ_START_TIME') || define('WZ_START_TIME', microtime(true));
    defined('WZ_START_MEM') || define('WZ_START_MEM', memory_get_usage());
    
    function load()
    {
        require_once 'wz/helpers.php';
        require_once 'Zend/Loader/Autoloader.php';
        $autoloader = \Zend_Loader_Autoloader::getInstance();
        $autoloader->setFallbackAutoloader(true);
        require_once(APPLICATION_PATH . '/../../../lib/ezComponents/Base/src/base.php');
        $autoloader->pushAutoloader(array('ezcBase', 'autoload'), 'ezc');
        
        $autoloader->pushAutoloader(function($className) {
            list($dummy, $class) = explode('WZ_', $className, 2);
            $class = strtolower($class);
            if ($class == 'store_object') {
                $class = 'storeobject';
            }
            require_once APPLICATION_PATH . "/../../../lib/wz/class.{$class}.php";
        }, 'WZ');
        $autoloader->pushAutoloader(function($className) {
            list($dummy, $class) = explode('WZHelper_', $className, 2);
            $class = strtolower($class);
            if (!strstr($class, '_')) {
                require_once APPLICATION_PATH . "/helpers/helper.{$class}.php";
            } else {
                list($module, $class) = explode('_', $class, 2);
                $module = ucfirst($module);
                $class = ucfirst($class);
                require_once APPLICATION_PATH . "/helpers/{$module}/{$class}.php";
            }
            $instance = new $className;
            if (method_exists($instance, 'init')) {
                $instance->init();
            }
        }, 'WZHelper');
        $autoloader->pushAutoloader(function($className) {
            list($dummy, $class) = explode('WZList_', $className, 2);
            $class = strtolower($class);
            if (!strstr($class, '_')) {
                require_once APPLICATION_PATH . "/lists/list.{$class}.php";
            } else {
                list($entity, $class) = explode('_', $class, 2);
                $entity = ucfirst($entity);
                $class = ucfirst($class);
                require_once APPLICATION_PATH . "/lists/{$entity}/{$class}.php";
            }
            $instance = new $className;
            if (method_exists($instance, 'init')) {
                $instance->init();
            }
        }, 'WZList');
        $autoloader->pushAutoloader(function($className) {
            list($dummy, $class) = explode('WZPlugin_', $className, 2);
            $class = strtolower($class);
            if (!strstr($class, '_')) {
                require_once APPLICATION_PATH . "/plugins/plugin.{$class}.php";
            } else {
                list($module, $class) = explode('_', $class, 2);
                $module = ucfirst($module);
                $class = ucfirst($class);
                require_once APPLICATION_PATH . "/plugins/{$module}/{$class}.php";
            }
            $instance = new $className;
            if (method_exists($instance, 'init')) {
                $instance->init();
            }
        }, 'WZPlugin');
        $autoloader->pushAutoloader(function($className) {
            list($dummy, $class) = explode('WZModel_', $className, 2);
            $class = strtolower($class);
            if (!strstr($class, '_')) {
                require_once APPLICATION_PATH . "/models/model.{$class}.php";
            } else {
                list($entity, $class) = explode('_', $class, 2);
                $entity = ucfirst($entity);
                $class = ucfirst($class);
                require_once APPLICATION_PATH . "/models/{$entity}/{$class}.php";
            }
            $instance = new $className;
            if (method_exists($instance, 'init')) {
                $instance->init();
            }
        }, 'WZModel');
        $autoloader->pushAutoloader(function($className) {
            list($dummy, $class) = explode('WZCrud_', $className, 2);
            $class = strtolower($class);
            if (!strstr($class, '_')) {
                require_once APPLICATION_PATH . "/models/crud/model.{$class}.php";
            } else {
                list($entity, $class) = explode('_', $class, 2);
                $entity = ucfirst($entity);
                $class = ucfirst($class);
                require_once APPLICATION_PATH . "/models/{$entity}/crud/{$class}.php";
            }
            $instance = new $className;
            if (method_exists($instance, 'init')) {
                $instance->init();
            }
        }, 'WZCrud');
        $autoloader->pushAutoloader(function($className) {
            list($dummy, $class) = explode('WZService_', $className, 2);
            $class = strtolower($class);
            if (!strstr($class, '_')) {
                require_once APPLICATION_PATH . "/services/service.{$class}.php";
            } else {
                list($entity, $class) = explode('_', $class, 2);
                $entity = ucfirst($entity);
                $class = ucfirst($class);
                require_once APPLICATION_PATH . "/services/{$entity}/{$class}.php";
            }
            $instance = new $className;
            if (method_exists($instance, 'init')) {
                $instance->init();
            }
        }, 'WZService');
        $autoloader->pushAutoloader(function($className) {
            list($dummy, $class) = explode('WZLib_', $className, 2);
            $class = strtolower($class);
            if (!strstr($class, '_')) {
                require_once APPLICATION_PATH . "/lib/lib.{$class}.php";
            } else {
                list($module, $class) = explode('_', $class, 2);
                $module = ucfirst($module);
                $class = ucfirst($class);
                require_once APPLICATION_PATH . "/lib/{$module}/{$class}.php";
            }
            $instance = new $className;
            if (method_exists($instance, 'init')) {
                $instance->init();
            }
        }, 'WZLib');
        $autoloader->pushAutoloader(function($className) {
            list($dummy, $class) = explode('WZForm_', $className, 2);
            $class = strtolower($class);            
            if (!strstr($class, '_')) {
                require_once APPLICATION_PATH . "/forms/form.{$class}.php";
            } else {
                list($entity, $class) = explode('_', $class, 2);
                $entity = ucfirst($entity);
                $class = ucfirst($class);
                require_once APPLICATION_PATH . "/forms/{$entity}/{$class}.php";
            }
            $instance = new $className;
            if (method_exists($instance, 'init')) {
                $instance->init();
            }
        }, 'WZForm');
    }
    
    load();
    class_alias('WZ_Utils', 'WZ');
    class_alias('WZ_Event', 'Event');
    class_alias('WZ_Singleton', 'Loader');
    class_alias('WZ_Logger', 'Logger');
